function buildItem(html) {
    return '<div class="form-item">' + html + '</div>';
}

function buildLine(html) {
    return '<div class="form-line">' + buildItem(html) + '</div>';
}

/**
 * 查询按钮
 */
function queryRows() {
    var opts = $('#query-form').form('options');
    console.log(opts);
    $.ajax({
        url: opts.url,
        contentType: 'application/json;charSet=utf-8',
        method: 'POST',
        data: JSON.stringify({type: 'sex'}),
        dataType: 'json',
        success: function (re) {
            if (re.state) {
                $('#datagrid-list').datagrid('loadData', re.data, "error");
            } else {
                $.messager.alert("错误消息", re.message);
            }
        }
    });
}

/**
 * 编辑按钮
 */
function editRow() {
    var rows = $('#datagrid-list').datagrid('getChecked');
    if (rows.length < 1) {
        $.messager.alert('提示消息', '请先选中一行,再进行编辑', 'warning');
    } else if (rows.length > 1) {
        $.messager.alert('提示消息', '每次只能编辑一行', 'warning');
    } else {
        console.log(rows[0]);
    }

}

/**
 * 删除按钮
 */
function deleteRow() {
    var rows = $('#datagrid-list').datagrid('getChecked');
    if (rows.length < 1) {
        $.messager.alert('提示消息', '没有选中要删除的行', 'warning');
    } else {
        $.messager.confirm('确定要删除吗', rows.length + '条记录即将被删除,确定要删除吗?', function (r) {
            if (r) {
                $.ajax({
                    url: '/sysdic/delete.json',

                });
            }
        });
    }
}

/**
 * 新增按钮
 */
function addRow() {
    var win = $('#open-win').length > 0 ? $('#open-win') : $('<div id="open-win"></div>').appendTo('body');
    win.window({
        title: '新增字典',
        width: 680,
        height: 500,
    }).window('window');
    build_sysdicedit();

}

/**
 * 表单提交
 */
function formSubmit() {
    var validate = $('#updateSysDic').form('validate');
    if (validate) {
        var url = $('#updateSysDic').form('options').url;
        var array = $('#updateSysDic').serializeArray();
        var data = {};
        $.each(array, function (index, item) {
            if (item.value) {
                data[item.name] = item.value;
            }
        });

        $.ajax({
            contentType: 'application/json;charSet=utf-8',
            url: url,
            method: 'POST',
            data: JSON.stringify(data),
            // dataType: 'JSON',
            success: function (rs) {
                console.log('success');
                console.log(rs);
            }
        });
    }
}
